package control;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.service.MovieService;
import model.vo.movie.MovieVO;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class MovieController extends MultiActionController {
	private MovieService movieService;
	public void setMovieService(MovieService movieService){
		this.movieService=movieService;
	}
	/**
	 * 영화메뉴 - 박스오피스 (초기화면)
	 */
	public ModelAndView getBoxOffice(HttpServletRequest request, HttpServletResponse response){
		System.out.println("getBoxOffice joi...");
		ArrayList<HashMap> list=null;
		try {
			list = movieService.getBoxOfficeList(); 
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return new ModelAndView("box_office.movie","list",list);
	}
	/**
	 * 영화메뉴 - 현재상영작
	 */
	public ModelAndView getScreeningMovie(HttpServletRequest request, HttpServletResponse response){
		ArrayList<HashMap> list=null;
		try {
			list = movieService.getScreeningMovie();	
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return new ModelAndView("screening.movie","list",list);
	}
	/**
	 * 영화메뉴 - 상영예정작
	 */
	public ModelAndView getUpcomingMovie(HttpServletRequest request, HttpServletResponse response){
		ArrayList<HashMap> list1=null;
		ArrayList<HashMap> list = new ArrayList<HashMap>();
		try {
			list1 = movieService.getUpcomingMovie();	
			for(HashMap map : list1){
				int d =Integer.parseInt(((BigDecimal) map.get("MOVIE_NO")).toString());	
				String day = movieService.dayCheck(d); //날짜비교
				if(day!=null){
					map.put("RESERVATION","DO");
				}else{
					map.put("RESERVATION", "DONT");
				}	
				list.add(map);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return new ModelAndView("upcoming.movie","list",list);
	}
	/**
	 * 영화의 상세정보 보이기
	 */
	public ModelAndView getMovieDetail(HttpServletRequest request, HttpServletResponse response){
		int movie_no = Integer.parseInt(request.getParameter("movie_no"));
		MovieVO vo=null;
		try {
			vo = movieService.getMovieDetail(movie_no);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return new ModelAndView("detail.movie","vo",vo);
	}
	
}
